
from datetime import datetime, timedelta, timezone
from jose import jwt
from typing import Optional
import uuid


# 加密秘钥
SECRET_KEY = "suhan@qq.com"
hours = 2

def create_access_token(user_id: str,
                       username:str,
                       hour:Optional[int] = int(hours))->str:
    # 设置过期时间
    expire_time = datetime.now() + timedelta(hours=hour)
    # exp 必传参数
    to_encode = {"exp": expire_time, "user_id": user_id, "username": username}
    # 生成token，algorithm使用 HS256 加密算法
    access_token = jwt.encode(to_encode, SECRET_KEY, algorithm='HS256')
    return access_token

expire = datetime.now(timezone.utc) + timedelta(hours=1)

print(uuid.uuid4().hex)

